package day240519_report.e5;

import java.time.LocalDate;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        Staff staff1 = new Staff("sta-1", "add-1", 26, "man", 5000, LocalDate.of(2023, 6, 5));
        Staff staff2 = new Staff("sta-2", "add-2", 35, "woman", 6500, LocalDate.of(2019, 3, 7));
        Teacher teacher1 = new Teacher("tea-1", "add-tea-1", 24, "woman", 6000, LocalDate.of(2024, 1, 6), "计算机", "软件工程", 3000);
        Teacher teacher2 = new Teacher("tea-2", "add-tea-2", 56, "man", 9000, LocalDate.of(1985, 7, 3), "计算机", "计算机科学与技术", 5000);
        SecurityGuard securityGuard1 = new SecurityGuard("sec-1", "add-sec-2", 58, "man", 4600, LocalDate.of(2005, 3, 5), "识别是否是在校师生", 3500);
        SecurityGuard securityGuard2 = new SecurityGuard("sec-2", "add-sec-1", 36, "man", 4600, LocalDate.of(2018, 3, 5), "拦截美团and饿了么", 3000);
        Dean dean1 = new Dean("dean-1", "add-dean-1", 56, "man", 10000, LocalDate.of(1990, 5, 7), "物理", "应用物理", 6000, 6000);
        Dean dean2 = new Dean("dean-2", "add-dean-2", 60, "man", 11000, LocalDate.of(1985, 7, 2), "医学", "临床医学", 6000, 6000);

        Staff persons[] = {staff1, staff2, teacher1, teacher2, securityGuard1, securityGuard2, dean1, dean2};
        printName(persons);
        System.out.println("=== 以上是输出名字 ===");

        printSalary(persons);
        System.out.println("=== 以上是输出工资 ===");

        sortBySalary(persons);
        printAll(persons);

        System.out.println("=== 以上是按工资排序后的结果 ===");

        sortByAge(persons);
        printAll(persons);

        System.out.println("=== 以上是按年龄排序后的结果 ===");

        sortByName(persons);
        printAll(persons);

        System.out.println("=== 以上是按名称排序后的结果 ===");

        sortByDateHired(persons);
        printAll(persons);

        System.out.println("=== 以上是按入职时间排序后的结果 ===");

    }

    //自己写了个输出所有的函数以检验排序函数
    private static void printAll(Staff[] persons) {
        for (Staff staff : persons) {
            System.out.println("Name: " + staff.getName() +
                    ", Salary: " + staff.getSalary() +
                    ", Age: " + staff.getAge() +
                    ", DateHired: " + staff.getDateHired());
        }
    }

    private static void printName(Staff[] persons) {
        for (Staff staff : persons) {
            System.out.println(staff.getName());
        }
    }

    private static void printSalary(Staff[] staffs) {
        for (Staff staff : staffs) {
            System.out.println(staff.getSalary());
        }
    }

    private static void sortBySalary(Staff[] staffs) {
        Arrays.sort(staffs, new SalaryComparator());
    }

    private static void sortByAge(Staff[] staffs) {
        Arrays.sort(staffs, new AgeComparator());
    }

    private static void sortByName(Staff[] staffs) {
        Arrays.sort(staffs, new NameComparator());
    }

    private static void sortByDateHired(Staff[] staffs) {
        Arrays.sort(staffs, new DateHiredComparator());
    }

}

/*
 * 接口（Interface）
 * 是一种抽象类型
 * 定义类应该实现的方法和属性，但不提供具体的实现
 * 弱耦合性（相对于继承）
 * 提高代码的灵活性、可维护性、可扩展性和可测试性
 * 使得程序更加健壮和易于维护
 * */
